package com.ambow.servlet;

import java.io.IOException;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ambow.dao.Book_query;


/**
 * Servlet implementation class System001Servlet
 */
@WebServlet("/System001Servlet")
public class System001Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public System001Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("UTF-8");  
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		Book_query book_query = new Book_query();
		List list = null;
		
		String book_name = request.getParameter("name");
		if(book_name!=null){
			byte[] b=book_name.getBytes("iso-8859-1");
			book_name = new String(b,"utf-8");

			list = book_query.bookinfo(book_name);

			request.setAttribute("bookinfo", list);
			request.getRequestDispatcher("pages/module/system/system001/book_detail.jsp").forward(request, response);
		}
		String allquery = request.getParameter("one");
        System.out.println(allquery);
		if(allquery.equals("allquery")){
			list= book_query.orderQuery();
			request.setAttribute("allinfo", list);
			request.getRequestDispatcher("pages/module/system/system001/order_list_name.jsp").forward(request, response);
		}
		else if(allquery.equals("allquery1")){
			list= book_query.orderQuery2();
			request.setAttribute("allinfo", list);
			request.getRequestDispatcher("pages/module/system/system001/order_list_name2.jsp").forward(request, response);
		}
		else if(allquery.equals("supplier_name")){
			String supplier_name=request.getParameter("textfield2");
//			byte[] b1=supplier_name.getBytes("iso-8859-1");
//			supplier_name = new String(b1,"utf-8");
//			System.out.println(supplier_name);
			list = book_query.orderQuery1(supplier_name);
			request.setAttribute("allinfo", list);
			request.getRequestDispatcher("pages/module/system/system001/order_list_name.jsp").forward(request, response);
			
		}
		else if(allquery.equals("supplier_name1")){
			String supplier_name=request.getParameter("machant");
//			byte[] b1=supplier_name.getBytes("iso-8859-1");
//			supplier_name = new String(b1,"utf-8");
//			System.out.println(supplier_name);
			list = book_query.orderQuery3(supplier_name);
			request.setAttribute("allinfo", list);
			request.getRequestDispatcher("pages/module/system/system001/order_list_name2.jsp").forward(request, response);
			
			
		}
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}

}
